package com.greyu.ysj.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.greyu.ysj.config.ResultStatus;
import com.greyu.ysj.entity.CbtAsset;
import com.greyu.ysj.entity.CbtFeedback;
import com.greyu.ysj.entity.User;
import com.greyu.ysj.mapper.CbtAssetMapper;
import com.greyu.ysj.mapper.CbtFeedbackMapper;
import com.greyu.ysj.model.ResultModel;
import com.greyu.ysj.service.CbtAssetService;
import com.greyu.ysj.service.CbtFeedBackService;
import com.greyu.ysj.utils.WalletAccount;
import com.greyu.ysj.utils.WalletProcess;
@Service
@Transactional
public class CbtFeedBackServiceImpl implements CbtFeedBackService {
	@Autowired
	private CbtFeedbackMapper cbtFeedbackMapper;
	
	@Override
	public ResultModel save(CbtFeedback cbtFeedback) {
		if(cbtFeedback.getWxId() == null || cbtFeedback.getPhone() == null
				|| cbtFeedback.getContent() == null) {
			return ResultModel.error(ResultStatus.DATA_NOT_NULL);
		}
		cbtFeedback.setStatus(2);
		cbtFeedback.setCreateDate(new Date());
		this.cbtFeedbackMapper.insert(cbtFeedback);
		return ResultModel.ok(cbtFeedback);
	}

	@Override
	public ResultModel update(int Id, CbtFeedback cbtFeedback) {
		CbtFeedback newFeedBack=this.selectById(Id);
		if(newFeedBack == null) {
			return ResultModel.error(ResultStatus.DATA_IS_NULL);
		}
		if(cbtFeedback.getStatus() != null) {
			newFeedBack.setStatus(cbtFeedback.getStatus());
		}
		
		newFeedBack.setUpdateDate(new Date());
		this.cbtFeedbackMapper.updateByPrimaryKey(newFeedBack);
		return ResultModel.ok(newFeedBack);
	}

	@Override
	public CbtFeedback selectById(int Id) {
		
		return this.cbtFeedbackMapper.selectByPrimaryKey(Id);
	}
	

}
